import sendRequest from "./request";

let type = process.env.VUE_APP_API_ENV === "dev" ? "dev" : "production";
let url = {
  dev: "https://zhuanti.qa.chebada.com/activityapiv2/",
  production: "https://zhuanti.chebada.com/activityapiv2/",
  t: "https://zhuanti.t.chebada.com/activityapi/Handler/",
  local: ""
};

const cashUrl =
  process.env.VUE_APP_API_ENV === "dev"
    ? "https://zhuanti.qa.chebada.com/gateway/cash/api/cash2wechat/"
    : "https://zhuanti.chebada.com/gateway/cash/api/cash2wechat/";

//service test
export const serviceTest = params => {
  return sendRequest("/serviceTestUrl", {
    data: params,
    serviceName: "serviceName"
    // method: 'get', //默认'post'
    // formateParam(param){ //针对请求参数与默认的不一致的情况，return新的数据格式
    //   return {...param}
    // },
    // formateRes(res){ //针对返回参数与默认的不一致的情况，return新的数据格式
    //   return {...res}
    // },
    // hideLoading： true, //是否隐藏loading， 默认false
    // manualRes: true //是否完全手动处理返回， 默认false
  });
};

export const mainApi = params => {
  return sendRequest({
    url: "/Anniversary2021",
    params: {
      data: params,
      serviceName: "annhome2021"
    },
    needLogin: true,
    hideLoading: true
  });
};

export const swiperApi = params => {
  return sendRequest({
    url: "/Anniversary2021",
    params: {
      data: params,
      serviceName: "annwinnings2021",
      hideLoading: true
    }
  });
};

export const uploadApi = params => {
  return sendRequest({
    url: "/Anniversary2021",
    params: {
      data: params,
      serviceName: "annupload2021"
    },
    needLogin: true
  });
};

export const drawApi = params => {
  return sendRequest({
    url: "/Anniversary2021",
    params: {
      data: params,
      serviceName: "annfirstlist2021",
      hideLoading: true
    },
    needLogin: false
  });
};

// 上传支付宝信息
export const updateApi = params => {
  return sendRequest({
    url: "/Anniversary2021",
    params: {
      data: params,
      serviceName: "anneditalipay2021",
      hideLoading: true
    },
    needLogin: true
  });
};

// 个人奖品
export const rewardApi = params => {
  return sendRequest({
    url: "/Anniversary2021",
    params: {
      data: params,
      serviceName: "annmyreward2021",
      hideLoading: true
    },
    needLogin: true
  });
};

// export const cashApi = params => {
//   return sendRequest({
//     url: "/Anniversary2021",
//     params: {
//       data: {
//         ...params,
//         operateType: "0",
//         // cashProductSerialId 随便传
//         cashProductSerialId: "x",
//         cashProductType: "3"
//       },
//       serviceName: "anntixian2021"
//     },
//     needLogin: true
//   });
// };

export const cashApi = params => {
  return sendRequest({
    url: cashUrl,
    params: {
      data: {
        ...params,
        cashProductType: "3",
        cashProductSerialid: new Date().getTime() + ""
      }
    },
    needLogin: true
  });
};

export const helpApi = params => {
  return sendRequest({
    url: "/Anniversary2021",
    params: {
      data: params,
      serviceName: "annhelp2021",
      hideLoading: true
    },
    needLogin: true
  });
};

// 同程风险控制
export const textfraud = params => {
  return sendRequest({
    url: `${url[type]}/CommonActivity`,
    params: {
      data: params,
      serviceName: "textfraud",
      hideLoading: true
    }
  });
};

export const activityrule = params => {
  return sendRequest({
    url: "/Anniversary2021",
    params: {
      data: params,
      serviceName: "activityrule",
      hideLoading: true
    },
    needLogin: false
  });
};
